package com.jspgou.cms.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.springframework.stereotype.Repository;

import com.jspgou.common.hibernate3.Finder;
import com.jspgou.common.hibernate3.HibernateBaseDao;
import com.jspgou.common.page.Pagination;
import com.jspgou.cms.dao.AftersaleTypeDao;
import com.jspgou.cms.entity.AftersaleType;

@Repository
public class AftersaleTypeDaoImpl extends HibernateBaseDao<AftersaleType, Long> implements AftersaleTypeDao {
	public Pagination getPage(int pageNo, int pageSize) {
		Criteria crit = createCriteria();
		Pagination page = findByCriteria(crit, pageNo, pageSize);
		return page;
	}

	public AftersaleType findById(Long id) {
		AftersaleType entity = get(id);
		return entity;
	}
	
	@SuppressWarnings("unchecked")
	public List<AftersaleType> findAll(){
		Finder f=Finder.create("from AftersaleType bean");
		return find(f);
	}
	
	@SuppressWarnings("unchecked")
	public List<AftersaleType> findByDeliver(Boolean deliver){
		Finder f=Finder.create("from AftersaleType bean where 1=1");
		if(deliver!=null){
			f.append(" and bean.deliver=:deliver");
			f.setParam("deliver", deliver);
		}
		return find(f);
	}

	public AftersaleType save(AftersaleType bean) {
		getSession().save(bean);
		return bean;
	}

	public AftersaleType deleteById(Long id) {
		AftersaleType entity = super.get(id);
		if (entity != null) {
			getSession().delete(entity);
		}
		return entity;
	}
	
	@Override
	protected Class<AftersaleType> getEntityClass() {
		return AftersaleType.class;
	}
}